<template>
	<view class="goods-item">

		<!-- 左侧盒子 -->
		<view class="left-goods-item">
			<radio :checked="item.goods_state" color="#C00000" v-if="showRadio" @click="radioClickHandler"></radio>
			<image class="goods-pic" :src="item.goods_small_logo || defaultPic" ></image>
		</view>
		
		<!-- 右侧盒子 -->
		<view class="right-goods-item">
			<!-- 商品名称 -->
			<view class="goods-name">
				{{item.goods_name}}
			</view>
			<!-- 商品信息 -->
			<view class="goods-info">
				<!-- 商品价格 -->
				<view class="goods-price">
					￥{{item.goods_price | tofixed}}
				</view>
				<!-- 商品数量 -->
				<uni-number-box :min="1" :value="item.goods_count" v-if="showNum" @change="numChangeHandler"></uni-number-box>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		props: {
			item: {
				type: Object,
				default: {}
			},
			showRadio: {
				type: Boolean,
				// 默认情况下不会展示radio
				default: false
			},
			showNum: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				// 默认图片
				defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
			};
		},
		methods: {
			radioClickHandler() {
				this.$emit('radio-change', {
					goods_id: this.item.goods_id,
					goods_state: !this.item.goods_state
				})
			},
			// 监听到了NumberBox数量变化事件
			numChangeHandler(val) {
				this.$emit('num-change',{
					goods_id: this.item.goods_id,
					goods_count: +val,
				})
				console.log(val)
			}
			
			
			
			
			
		},
		// 过滤器
		filters: {
			tofixed(num) {
				return Number(num).toFixed(2)
			}
		}
	}
</script>

<style lang="scss">
	.goods-item {
		display: flex;
		padding: 10rpx 20rpx;
		border-bottom: 5rpx solid #f0f0f0;
		background-color: white;
		.left-goods-item {
			margin-right: 20rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			.goods-pic {
				height: 220rpx;
				width: 220rpx;
				display: block;
				border-radius: 10rpx;
			}
			
		}
		
		.right-goods-item{
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			.goods-name {
				font-size: 28rpx;
			}
			
			.goods-info{
				display: flex;
				justify-content: space-between;
				align-content: center;
				.goods-price{
					color: #C00000;
					font-size: 35rpx;
				}
			}
		}
	}
</style>
